/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Text, Button, LineColumn,} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, SelectPair, SelectValDescPair, useItemInputControl,
} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {objNestSet} from "../../../common/tool";
import {JumpOrgTag} from "../../common/general";

//可以复用的组件： 尽量抽象 和 提高代码复用程度！
interface Props  extends InternalItemProps{
    config: any[];    //有配置模式的 : 表对象的默认取值；
}

const itemA动态项=['_Oitems'];
const 类别3态: SelectValDescPair[]=[ ['A',"A类"],['B',"B类"],[' ',"非A非B类"] ];
export const 自定项类=[['4.5','B'],['4.6','B'],['6.10','B'],['6.11','B'], ['6.14(2)','B'],['6.19','B'],
    ['7.5(2)','B'],['7.7(2)','B'],['7.9','B'], ['8.9','B'],['11.2(2)','B'],['11.5','B'],['11.6','B'],['12.8','B'],
    ['12.11','B'],['12.12','B'],['14.8','B'],
];
/**【特殊】用户添加的检验项目; 支持 非自拆分的 简单项目。 只能支持二级的标题配置。
 * */
export const CategorySet=
    React.forwardRef((
        { children, show ,alone=true,redId,nestMd,label,config}:Props,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null,itemA动态项, );
        const {inp, setInp} = useItemInputControl({ ref });
        return <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} redId={redId}
                                    nestMd={nestMd}
                                    alone={alone} label={label!}>
            <Text variant="h5">
              {label}；
            </Text>这是动态项，要首先配置，若半道上改了，不合格项目表需要重新初始化，才能确保一致。
            <Button onPress={() => {setInp({ ...inp, _Oitems: undefined})} }>清空全表至默认</Button>
            <hr/>
            <LineColumn>
                { config.map(([item,dfClass],  w:number) => {
                    return <div key={w} css={{display:'flex',justifyContent:'center',alignItems:'center',flexWrap:'wrap'}}>
                        <Text variant="h5">{`${item}-类别`}</Text>
                        <SelectPair value={inp?._Oitems?.[item] || dfClass} dlist={类别3态}
                               onChange={e =>objNestSet('_Oitems', item, e.currentTarget.value||undefined,inp,setInp) }/>
                        <JumpOrgTag big tag={item}>转</JumpOrgTag>
                    </div>
                }) }
            </LineColumn>
            {children}
        </InspectRecordLayout>;
});
